angular.module("config")
    .controller("complaintController", function ($scope,$http,$location) {
        var req = {
            method:"GET",
            url:"/order/complaint"
        }
        $http(req)
            .then(function (res) {
                for(var key in res.data){
                    var foodList=res.data[key].foodInfo;
                    var sum=0;
                    for(var key1 in foodList){
                        sum+=foodList[key1].num*foodList[key1].item.fPrice;
                    }
                    res.data[key].sum=sum;
                }
                $scope.complaintOrders=res.data;
            })

        $scope.handle=function (key) {
            console.log(key);
            $scope.complaint=$scope.complaintOrders[key].complaint;
            // for(var key in $scope.complaintOrders){
            //     if( oId === $scope.complaintOrders[key]._id){
            //         $scope.complaint=$scope.complaintOrders[key].complaint;
            //     }
            // }
            var req={
                method:"GET",
                url:"/order/"+$scope.complaintOrders[key]._id+"?Rand="+Math.random()
            }
            $http(req)
                .then(function (res) {
                    console.log(res.data);
                    $scope.handleResult=res.data.oStatus;
                })
        }

        $scope.$on('UserLogout', function (event,data) {
            $location.path("#/");
        });



        $scope.$emit("changeTopStyle", true);
    });
